package com.kaikeba.dao.Impl;

import com.kaikeba.bean.Express;
import com.kaikeba.dao.BaseExpressDao;
import com.kaikeba.exception.DuplicateCodeException;
import org.junit.Test;

import java.util.List;
import java.util.Map;


public class ExpressDaoMySqlTest {
    BaseExpressDao dao = new ExpressDaoMySql();

    @Test
    public void console() {
        List<Map<String, Integer>> console = dao.console();
        System.out.println(console);
    }

    @Test
    public void findAll() {
        //System.out.println(dao.findAll(true, 2, 3));
        System.out.println(dao.findAll(false,0,0));
    }

    @Test
    public void findByNumber() {
        System.out.println(dao.findByNumber("124"));
    }

    @Test
    public void findByCode() {
        System.out.println(dao.findByCode("223456"));
    }

    @Test
    public void findByUserPhone() {
        //System.out.println(dao.findByUserPhone("13843838438"));
        System.out.println(dao.findByUserPhone("14843838438"));
    }

    @Test
    public void findBySysPhone() {
        System.out.println(dao.findBySysPhone("18888888888"));
    }

    @Test
    public void insert() {
        Express e = new Express("888888","哄哄8","13843838438","韵达快递","1888888888","666666");
        //String number, String username, String userPhone, String company, String sysPhone
        boolean insert = false;
        try {
            insert = dao.insert(e);
        } catch (DuplicateCodeException duplicateCodeException) {
            System.out.println("取件码重复的异常被捕获到了");
        }
        System.out.println(insert);
    }

    @Test
    public void insert2() {
        //Express e = new Express("888888","哄哄8","13843838438","韵达快递","1888888888","666666");
        //String number, String username, String userPhone, String company, String sysPhone
        boolean insert = false;
        try {
            for (int i=0;i<100;i++) {
                Express e = new Express("10000"+i,"哄哄8","13843838438","韵达快递","1888888888","666000"+i);
                insert = dao.insert(e);
            }
        } catch (DuplicateCodeException duplicateCodeException) {
            System.out.println("取件码重复的异常被捕获到了");
        }
        System.out.println(insert);
    }

    @Test
    public void update() {
        Express e = new Express();
        e.setNumber("1114");
        e.setCompany("哄哄快递");
        e.setUsername("王二");
        e.setStatus(0);
        System.out.println(dao.update(1,e));
    }

    @Test
    public void updateStatus() {
        System.out.println(dao.updateStatus("666666"));
    }

    @Test
    public void delete() {
        System.out.println(dao.delete(1));
    }
}